package com.woniuxy01;

import java.io.*;

/**
 * @author 作者
 * @create 2025-08-01 14:31
 */
public class Test05 {
    public static void main(String[] args) throws IOException {
        long start = System.currentTimeMillis();
        //???
//        copyFileByte("d:\\aaa\\a.pdf","d:\\aaa\\b.pdf");
        //1118
//        copyFileBytes("d:\\aaa\\a.pdf","d:\\aaa\\b.pdf");
        //4416
//        copyFileByteBuffered("d:\\aaa\\a.pdf","d:\\aaa\\b.pdf");
        //289
        copyFileBytesBuffered("d:\\aaa\\a.pdf", "d:\\aaa\\b.pdf");
        long end = System.currentTimeMillis();
        System.out.println(end - start);
    }

    private static void copyFileBytesBuffered(String source, String target) throws IOException {
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(source));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(target));
        int length = 0;
        byte[] bytes = new byte[1024];
        while ((length = bis.read(bytes)) != -1) {
            bos.write(bytes, 0, length);
        }
        bos.close();
        bis.close();
    }

    private static void copyFileByteBuffered(String source, String target) throws IOException {
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(source));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(target));
        int mybyte = 0;
        while ((mybyte = bis.read()) != -1) {
            bos.write(mybyte);
        }
        bos.close();
        bis.close();
    }


    private static void copyFileBytes(String source, String target) throws IOException {
        FileInputStream fis = new FileInputStream(source);
        FileOutputStream fos = new FileOutputStream(target);
        //文件复制:一次读取一个字节数组，一次写一个字节数组
        int length = 0;
        byte[] bytes = new byte[1024];
        while ((length = fis.read(bytes)) != -1) {
            fos.write(bytes, 0, length);
        }
        fos.close();
        fis.close();
    }


    private static void copyFileByte(String source, String target) throws IOException {
        FileInputStream fis = new FileInputStream(source);
        FileOutputStream fos = new FileOutputStream(target);
        //文件复制:一次读取一个字节，一次写一个字节
        int mybyte = 0;
        while ((mybyte = fis.read()) != -1) {
            fos.write(mybyte);
        }
        fos.close();
        fis.close();
    }


}
